package day01_IO_JDBC.demo_JDBC_emp.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtils {

/*
* 加载驱动
* */

//    定义 4 常量
    private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
    private static final String URL= "jdbc://mysql://localhost:3306/airui_jdbc_demo";
    private static final String username="root";
    private static final String pwd="123456";

//    定义 getConnection() 方法
    public static Connection getConnection(){
//        定义 connection变量
        Connection connection = null;

//        加载驱动
        try {
            Class.forName(DRIVER);

//            通过 DriverManager 给 connection 赋值 URL,username,pwd
            connection= DriverManager.getConnection(URL,username,pwd);
            return connection;
        } catch (ClassNotFoundException e) {
            e.getStackTrace();
        } catch (SQLException e) {
            e.getStackTrace();
        }

        return connection;
    }


}
